from matplotlib import pyplot as plt

colors = ['blue', 'green', 'red', 'brown', 'cyan', 'lime', 'magenta', 'yellow', 'indigo', 'orange', 'pink']
linestyles = ['-', '--', '-.', ':']
markers = ['o', 's', '^', 'v', 'D', 'p', 'h', '8', '<', '>']

def set_defaults(columns=1,subplots=1):
    """
    set defaults for desired format
    columns - integer number of columns for paper (1 or 2)
    subplots - integer number of subplots in the figure (1,2,4)
    """
    # Note: use \showthe\columnwidth / 72.27 to determine figure width
    # (inches)
    plt.rcdefaults()
    params = {'legend.numpoints':2,
             'legend.scatterpoints':1}
    plt.rcParams.update(params)
    if columns == 1:
        params = {'backend':'ps',
                  'figure.figsize':[6.3,4.1],
                  'figure.subplot.left':0.1,
                  'figure.subplot.right':0.95,
                  'figure.subplot.top':0.95,
                  'figure.subplot.bottom':0.15,
                  'figure.subplot.wspace':0.3,
                  'figure.subplot.hspace':0.2,
                  'font.size':12,
                  'font.weight':'light',
                  'axes.labelsize':12,
                  'text.fontsize':10,
                  'xtick.labelsize':10,
                  'ytick.labelsize':10,
                  'lines.linewidth':.8,
                  'lines.markersize':4,
                  'legend.fontsize':10,
                  'legend.markerscale':.8,
                  'legend.handlelength':2}
        plt.rcParams.update(params)
        if subplots == 4:
            params = {'figure.figsize':[6.3,5.7],
                      'figure.subplot.left':0.11,
                      'figure.subplot.right':0.97,
                      'figure.subplot.top':0.94,
                      'figure.subplot.bottom':0.09,
                      'font.size':10,
                      'font.weight':'medium',
                      'axes.labelsize':10,
                      'text.fontsize':9,
                      'xtick.labelsize':8,
                      'ytick.labelsize':8,
                      'lines.linewidth':.8,
                      'lines.markersize':4,
                      'legend.fontsize':8,
                      'legend.handlelength':3,
                      'legend.markerscale':.6}
            plt.rcParams.update(params)
        if subplots == 6:
            params = {'figure.figsize':[6.5,8.5],
                      'figure.subplot.left':0.11,
                      'figure.subplot.right':0.97,
                      'figure.subplot.top':0.97,
                      'figure.subplot.bottom':0.07,
                      'font.size':10,
                      'font.weight':'medium',
                      'axes.labelsize':10,
                      'text.fontsize':9,
                      'xtick.labelsize':8,
                      'ytick.labelsize':8,
                      'lines.linewidth':.8,
                      'lines.markersize':4,
                      'legend.fontsize':8,
                      'legend.handlelength':3,
                      'legend.markerscale':.8}
            plt.rcParams.update(params)
    if columns == 2:
        params = {'backend':'ps',
                  'figure.figsize':[3.4,2.3],
                  'figure.subplot.left':0.18,
                  'figure.subplot.right':0.94,
                  'figure.subplot.top':0.95,
                  'figure.subplot.bottom':0.19,
                  'figure.subplot.wspace':0.4,
                  'figure.subplot.hspace':0.3,
                  'font.size':8,
                  'font.weight':'light',
                  'axes.labelsize':9,
                  'axes.linewidth':0.8,
                  'text.fontsize':8,
                  'xtick.labelsize':7,
                  'ytick.labelsize':7,
                  'lines.linewidth':.7,
                  'lines.markersize':3,
                  'legend.fontsize':7,
                  'legend.markerscale':.7,
                  'legend.frameon':False,
                  'legend.handlelength':3.4 }
        plt.rcParams.update(params)
        if subplots == 4:
            params = {'figure.figsize':[3.4,2.3],
                      'figure.subplot.left':0.15,
                      'figure.subplot.right':0.96,
                      'figure.subplot.top':0.97,
                      'figure.subplot.bottom':0.19,
                      'figure.subplot.wspace':0.4,
                      'figure.subplot.hspace':0.3,
                      'font.size':7,
                      'font.weight':'medium',
                      'axes.labelsize':8,
                      'axes.linewidth':0.9,
                      'text.fontsize':7,
                      'xtick.labelsize':6,
                      'ytick.labelsize':6,
                      'xtick.major.pad': 3,
                      'ytick.major.pad': 2,
                      'lines.linewidth':.7,
                      'lines.markersize':3,
                      'legend.labelspacing':0.5,
                      'legend.frameon':False,
                      'legend.handlelength':3.4,
                      'legend.fontsize':6}
            plt.rcParams.update(params)

        if subplots == 6:
            params = {'figure.figsize':[3.2,4.3],
                      'figure.subplot.left':0.15,
                      'figure.subplot.right':0.96,
                      'figure.subplot.top':0.97,
                      'figure.subplot.bottom':0.12,
                      'font.size':7,
                      'font.weight':'medium',
                      'axes.labelsize':8,
                      'axes.linewidth':0.9,
                      'text.fontsize':7,
                      'xtick.labelsize':6,
                      'ytick.labelsize':6,
                      'xtick.major.pad': 3,
                      'ytick.major.pad': 2,
                      'lines.linewidth':.7,
                      'lines.markersize':3,
                      'legend.labelspacing':0.5,
                      'legend.frameon':False,
                      'legend.handlelength':3.4,
                      'legend.fontsize':6}
            plt.rcParams.update(params)

class Defaults(object):
    """
    Class to set defaults for matplotlib figures for multicolumn papers and plots
    """
    def __init__(self):
        """
        Instantiation
        """
        self.linecolors = ['blue', 'green', 'red', 'brown', 'cyan', 'lime', 'magenta', 'yellow', 'indigo', 'orange', 'pink']
        self.linestyles = ['-', '--', '-.', ':']
        self.markers = ['s', '<', '>', 'v', '^', 's','p']

    def set_defaults(self,columns=1,subplots=1):
        """
        set defaults for desired format
        columns - integer number of columns for paper (1 or 2)
        subplots - integer number of subplots in the figure (1,2,4)
        """
        # Note: use \showthe\columnwidth / 72.27 to determine figure width
        # (inches)
        plt.rcdefaults()
        params = {'legend.numpoints':2,
                 'legend.scatterpoints':1}
        plt.rcParams.update(params)
        if columns == 1:
            params = {'backend':'ps',
                      'figure.figsize':[6.3,4.1],
                      'figure.subplot.left':0.1,
                      'figure.subplot.right':0.95,
                      'figure.subplot.top':0.95,
                      'figure.subplot.bottom':0.15,
                      'figure.subplot.wspace':0.3,
                      'figure.subplot.hspace':0.2,
                      'font.size':12,
                      'font.weight':'light',
                      'axes.labelsize':12,
                      'text.fontsize':10,
                      'xtick.labelsize':10,
                      'ytick.labelsize':10,
                      'lines.linewidth':.8,
                      'lines.markersize':4,
                      'legend.fontsize':10,
                      'legend.markerscale':.8,
                      'legend.handlelength':2}
            plt.rcParams.update(params)
            if subplots == 4:
                params = {'figure.figsize':[6.3,5.7],
                          'figure.subplot.left':0.11,
                          'figure.subplot.right':0.97,
                          'figure.subplot.top':0.94,
                          'figure.subplot.bottom':0.09,
                          'font.size':10,
                          'font.weight':'medium',
                          'axes.labelsize':10,
                          'text.fontsize':9,
                          'xtick.labelsize':8,
                          'ytick.labelsize':8,
                          'lines.linewidth':.8,
                          'lines.markersize':4,
                          'legend.fontsize':8,
                          'legend.handlelength':3,
                          'legend.markerscale':.6}
                plt.rcParams.update(params)
            if subplots == 6:
                params = {'figure.figsize':[6.5,8.5],
                          'figure.subplot.left':0.11,
                          'figure.subplot.right':0.97,
                          'figure.subplot.top':0.97,
                          'figure.subplot.bottom':0.07,
                          'font.size':10,
                          'font.weight':'medium',
                          'axes.labelsize':10,
                          'text.fontsize':9,
                          'xtick.labelsize':8,
                          'ytick.labelsize':8,
                          'lines.linewidth':.8,
                          'lines.markersize':4,
                          'legend.fontsize':8,
                          'legend.handlelength':3,
                          'legend.markerscale':.8}
                plt.rcParams.update(params)
        if columns == 2:
            params = {'backend':'ps',
                      'figure.figsize':[3.2,2.1],
                      'figure.subplot.left':0.18,
                      'figure.subplot.right':0.94,
                      'figure.subplot.top':0.95,
                      'figure.subplot.bottom':0.22,
                      'figure.subplot.wspace':0.4,
                      'figure.subplot.hspace':0.3,
                      'font.size':8,
                      'font.weight':'light',
                      'axes.labelsize':9,
                      'axes.linewidth':0.8,
                      'text.fontsize':8,
                      'xtick.labelsize':7,
                      'ytick.labelsize':7,
                      'lines.linewidth':.7,
                      'lines.markersize':3,
                      'legend.fontsize':7,
                      'legend.markerscale':.7,
                      'legend.frameon':False,
                      'legend.handlelength':3.4 }
            plt.rcParams.update(params)
            if subplots == 4:
                params = {'figure.figsize':[3.2,2.9],
                          'figure.subplot.left':0.15,
                          'figure.subplot.right':0.96,
                          'figure.subplot.top':0.97,
                          'figure.subplot.bottom':0.12,
                          'font.size':7,
                          'font.weight':'medium',
                          'axes.labelsize':8,
                          'axes.linewidth':0.9,
                          'text.fontsize':7,
                          'xtick.labelsize':6,
                          'ytick.labelsize':6,
                          'xtick.major.pad': 3,
                          'ytick.major.pad': 2,
                          'lines.linewidth':.7,
                          'lines.markersize':3,
                          'legend.labelspacing':0.5,
                          'legend.frameon':False,
                          'legend.handlelength':3.4,
                          'legend.fontsize':6}
                plt.rcParams.update(params)

            if subplots == 6:
                params = {'figure.figsize':[3.2,4.3],
                          'figure.subplot.left':0.15,
                          'figure.subplot.right':0.96,
                          'figure.subplot.top':0.97,
                          'figure.subplot.bottom':0.12,
                          'font.size':7,
                          'font.weight':'medium',
                          'axes.labelsize':8,
                          'axes.linewidth':0.9,
                          'text.fontsize':7,
                          'xtick.labelsize':6,
                          'ytick.labelsize':6,
                          'xtick.major.pad': 3,
                          'ytick.major.pad': 2,
                          'lines.linewidth':.7,
                          'lines.markersize':3,
                          'legend.labelspacing':0.5,
                          'legend.frameon':False,
                          'legend.handlelength':3.4,
                          'legend.fontsize':6}
                plt.rcParams.update(params)
